/*
 * Copyright (c) 2016. 恒昌互联网运营中心.
 */
package com.credithc.eagleeye.console.web;
import com.credithc.eagleeye.console.service.StatService;
import com.credithc.eagleeye.console.vo.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * <br>
 * 类 名: StatController <br>
 * 描 述: 统计 <br>
 * 作 者: zj <br>
 * 创 建： 2018年09月27日 <br>
 * 版 本：v1.0.0 <br>
 * <br>
 * 历 史: (版本) 作者 时间 注释
 */
@Controller
@RequestMapping("/stat")
public class StatController extends AbstractAction {
	private static final Logger logger = LoggerFactory.getLogger(StatController.class);


	@Autowired
	private StatService statService;

	@Override
	protected String getFlag() {
		return "stat_flag";
	}

	@Override
	protected String getTitle() {
		return "鹰眼统计报表";
	}

	@RequestMapping(value = "main", method = RequestMethod.GET)
	public String main(HttpServletRequest request, ModelMap map) {
		putPublicAttribute(map);
		putPlatformListAttribute(request,map);
		return "stat/statMain";
	}

	@RequestMapping(value = "getEnums", method = {RequestMethod.GET})
	@ResponseBody
	public ResultVo<EnumVo> getEnums(String platform,String env, HttpServletRequest request, ModelMap map) {
		ResultVo<EnumVo> resultVo=new ResultVo();
		try {
			EnumVo enumVo = this.statService.statEnum(platform, env);
			resultVo.setData(enumVo);
			resultVo.setCode("1");
		} catch (Exception e) {
			e.printStackTrace();
			resultVo.setCode("0");
			resultVo.setMessage(e.getMessage());
		}

		return resultVo;
	}
	@RequestMapping(value = "statError", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public ResultVo<List<StatVo>> statError(StatConditionVo statConditionVo, ModelMap map) {
		putPublicAttribute(map);
		ResultVo<List<StatVo>> resultVo=new ResultVo();
		try {
			List<StatVo> resultList = this.statService.statError(statConditionVo);
			resultVo.setCode("1");
			resultVo.setData(resultList);
			resultVo.setMessage("处理成功！");
		} catch (Exception e) {
			e.printStackTrace();
			resultVo.setCode("0");
			resultVo.setMessage(e.getMessage());
		}

		return resultVo;
	}

	@RequestMapping(value = "statPercent", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public ResultVo<List<StatVo>> statPercent(StatConditionVo statConditionVo, ModelMap map) {
		putPublicAttribute(map);
		ResultVo<List<StatVo>> resultVo=new ResultVo();
		try {
			List<StatVo> resultList = this.statService.statPercent(statConditionVo);
			resultVo.setCode("1");
			resultVo.setData(resultList);
			resultVo.setMessage("处理成功！");
		} catch (Exception e) {
			e.printStackTrace();
			resultVo.setCode("0");
			resultVo.setMessage(e.getMessage());
		}

		return resultVo;
	}

	@RequestMapping(value = "statDependency", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public ResultVo<List<StatVo>> statDependency(StatConditionVo statConditionVo, ModelMap map) {
		putPublicAttribute(map);
		ResultVo<List<StatVo>> resultVo=new ResultVo();
		try {
			List<StatVo> resultList = this.statService.statDependency(statConditionVo);
			resultVo.setCode("1");
			resultVo.setData(resultList);
			resultVo.setMessage("获取依赖服务成功！");
		} catch (Exception e) {
			e.printStackTrace();
			resultVo.setCode("0");
			resultVo.setMessage(e.getMessage());
		}

		return resultVo;
	}
	@RequestMapping(value = "statSunburst", method = {RequestMethod.GET,RequestMethod.POST})
	@ResponseBody
	public ResultVo<List<StatSunburstVo>> statSunburst(StatConditionVo statConditionVo, ModelMap map) {
		putPublicAttribute(map);
		ResultVo<List<StatSunburstVo>> resultVo=new ResultVo();
		try {
			List<StatSunburstVo> resultList = this.statService.statSunburst(statConditionVo);
			resultVo.setCode("1");
			resultVo.setData(resultList);
			resultVo.setMessage("获取旭日图成功！");
		} catch (Exception e) {
			e.printStackTrace();
			resultVo.setCode("0");
			resultVo.setMessage(e.getMessage());
		}

		return resultVo;
	}
}
